<template>
	<view>
		<view class="backGroundBox">
		
		</view>
		<view class="" style="background: #FFFFFF">
			<!-- 搜索框 -->
			<view class="inputBox">
				<input type="text" @confirm="search" class="phoneInput" value="" v-model="deviceName"
					placeholder="请输入设备名称" />
				<image src="../../static/image/search.png" mode=""></image>
			</view>
		</view>
		<view class="devicBox">
			<view class="devicRow" v-for="(item,index) in list" :key="index">
				<view class="rowTop">
					<text class="deicName">{{item.deviceName}}</text>
					<view class="radioBox" v-if="item.network == 1">
						<view class="activeRadio">

						</view>
						<text class="radioText">在线</text>
					</view>
					<view class="radioBox" v-else>
						<view class="activeRadio" style="background: gray;">

						</view>
						<text class="radioText">离线</text>
					</view>
				</view>

				<view class="rowButtom">
					<view class="leftBox">
						<view class="">
							{{item.address}}

						</view>
						<view class="">
							当前柜内商品 <text class="numText"> {{item.stockName}} </text> 瓶
						</view>
					</view>
					<view class="rightBtn" @click="deviceClick(item)">
						补货
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: '',
				list: [],
				pageSize: 10,
				pageNumber: 1,
				deviceName: '',
				isLoadMore: false,
			}
		},
		onReachBottom() {
			if (this.isLoadMore) {
				this.pageNumber += 1
				this.getData()
			}
		},
		methods: {
			deviceClick(row) {
				console.log(row)
				uni.navigateTo({
					url: '../setRemined/currentDevice/currentDevice?id=' + row.id
				})
			},
			search(){
				this.pageNumber = 1
				this.list = []
				this.getData()
			},
			// 获取设备列表
			getData() {
				this.http({
					url: "/device/deviceList",
					data: {
						pageSize: this.pageSize,
						pageNumber: this.pageNumber,
						isAmple: '',
						deviceName: this.deviceName
					},
					method: "POST",
					success: res => {
						if (res.code == 200) {
							this.list = this.list.concat(res.data.list)
							if (res.data.list.length < this.pageSize) {
								this.isLoadMore = false
							} else {
								this.isLoadMore = true
							}
						}
					}
				})
			}
		},
		onShow() {
			this.list = []
			this.getData()
		},
		onLoad() {
		}
	}
</script>

<style>
	.inputBox {
		position: relative;
		display: flex;
		justify-content: center;
	}

	.inputBox image {
		width: 24rpx;
		height: 24rpx;
		position: absolute;
		top: 77rpx;
		left: 38rpx;
	}

	.phoneInput {
		margin-top: 50rpx;
		margin-bottom: 40rpx;
		height: 76rpx;
		border: 1px solid #E32929;
		opacity: 1;
		align-items: center;
		border-radius: 44rpx;
		padding-left: 50rpx;
		width: 88%;
	}

	.devicBox {
		width: 100%;
		background: #FAFAF9;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
	}

	.devicRow {
		/* height: 205rpx; */
		background: #FFFFFF;
		opacity: 1;
		border-radius: 10rpx;
		padding: 30rpx;
		margin-bottom: 13rpx;
	}

	.rowTop {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.deicName {
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #000000;
		opacity: 1;
		width: 80%;
		overflow: hidden;
		word-break: break-all;
		/* break-all(允许在单词内换行。) */
		text-overflow: ellipsis;
		/* 超出部分省略号 */
		display: -webkit-box;
		/** 对象作为伸缩盒子模型显示 **/
		-webkit-box-orient: vertical;
		/** 设置或检索伸缩盒对象的子元素的排列方式 **/
		-webkit-line-clamp: 1;
		/** 显示的行数 **/
	}

	.radioBox {
		display: flex;
		align-items: center;
	}

	.activeRadio {
		width: 12rpx;
		height: 12rpx;
		background: #0AAB24;
		border-radius: 50%;
		opacity: 1;
		margin-right: 15rpx;
	}

	.rowButtom {
		align-items: center;
		display: flex;
		margin-top: 35rpx;
		justify-content: space-between;
	}

	.leftBox {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		line-height: 48rpx;
		color: rgba(0, 0, 0, 0.65);
		opacity: 1;
	}

	.numText {
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #E32929;
	}

	.radioText {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: rgba(0, 0, 0, 0.65);

	}
    .backGroundBox {
    	position: fixed;
    	z-index: -1;
    	width: 100vw;
    	height: 100vh;
    	top: 0;
    	left: 0;
    	background: #FAFAF9;
    }
	.rightBtn {
		width: 126rpx;
		height: 56rpx;
		background: #E32929;
		opacity: 1;
		border-radius: 5rpx;
		color: white;
		text-align: center;
		line-height: 56rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;

	}
</style>
